b542a18f4500469f70141f00ec14bf5a4768b448,servers/src/main/java/tachyon/worker/block/evictor/NaiveEvictor.java,NaiveEvictor,freeSpace,#number#BlockStoreLocation#,43

Before Change


  }

  @Override
  public Optional<EvictionPlan> freeSpace(long bytes, BlockStoreLocation location) {
    List<Pair<Long, BlockStoreLocation>> toMove = new ArrayList<Pair<Long, BlockStoreLocation>>();
    List<Long> toEvict = new ArrayList<Long>();

    long spaceFreed = 0;
    if (location.equals(BlockStoreLocation.anyTier())) {
      for (StorageTier tier : mMetaManager.getTiers()) {
        for (StorageDir dir : tier.getStorageDirs()) {
          for (BlockMeta block : dir.getBlocks()) {
            toEvict.add(block.getBlockId());
            spaceFreed += block.getBlockSize();
            if (spaceFreed >= bytes) {
              return Optional.of(new EvictionPlan(toMove, toEvict));
            }
          }
        }
      }
      return Optional.absent();
    }

    int tierAlias = location.tierAlias();
    StorageTier tier = mMetaManager.getTier(tierAlias);
    if (location.equals(BlockStoreLocation.anyDirInTier(tierAlias))) {
      // Loop over all dirs in the given tier
      for (StorageDir dir : tier.getStorageDirs()) {
        for (BlockMeta block : dir.getBlocks()) {
          toEvict.add(block.getBlockId());
          spaceFreed += block.getBlockSize();
          if (spaceFreed >= bytes) {
            return Optional.of(new EvictionPlan(toMove, toEvict));
          }
        }
      }
      return Optional.absent();
    }

    int dirIndex = location.dir();
    StorageDir dir = tier.getDir(dirIndex);
    for (BlockMeta block : dir.getBlocks()) {
      toEvict.add(block.getBlockId());
      spaceFreed += block.getBlockSize();
      if (spaceFreed >= bytes) {
        return Optional.of(new EvictionPlan(toMove, toEvict));
      }

After Change


  }

  @Override
  public Optional<EvictionPlan> freeSpace(long availableBytes, BlockStoreLocation location) {
    List<Pair<Long, BlockStoreLocation>> toMove = new ArrayList<Pair<Long, BlockStoreLocation>>();
    List<Long> toEvict = new ArrayList<Long>();

    long freed = 0;
    long available = mMetaManager.getAvailableBytes(location);
    if (available >= availableBytes) {
      // The current space is sufficient, no need for eviction
      return Optional.of(new EvictionPlan(toMove, toEvict));
    }

    if (location.equals(BlockStoreLocation.anyTier())) {
      for (StorageTier tier : mMetaManager.getTiers()) {
        for (StorageDir dir : tier.getStorageDirs()) {
          for (BlockMeta block : dir.getBlocks()) {
            toEvict.add(block.getBlockId());
            freed += block.getBlockSize();
            if (available + freed >= availableBytes) {
              return Optional.of(new EvictionPlan(toMove, toEvict));
            }
          }
        }
      }
      return Optional.absent();
    }

    int tierAlias = location.tierAlias();
    StorageTier tier = mMetaManager.getTier(tierAlias);
    if (location.equals(BlockStoreLocation.anyDirInTier(tierAlias))) {
      // Loop over all dirs in the given tier
      for (StorageDir dir : tier.getStorageDirs()) {
        for (BlockMeta block : dir.getBlocks()) {
          toEvict.add(block.getBlockId());
          freed += block.getBlockSize();
          if (available + freed >= availableBytes) {
            return Optional.of(new EvictionPlan(toMove, toEvict));
          }
        }
      }
      return Optional.absent();
    }

    int dirIndex = location.dir();
    StorageDir dir = tier.getDir(dirIndex);
    for (BlockMeta block : dir.getBlocks()) {
      toEvict.add(block.getBlockId());
      freed += block.getBlockSize();
      if (available + freed >= availableBytes) {
        return Optional.of(new EvictionPlan(toMove, toEvict));
      }